package com.yyds.controller;

import com.yyds.common.MyJSON;
import com.yyds.common.R;
import com.yyds.pojo.NatSites;
import com.yyds.service.NatSitesService;
import com.yyds.vo.EchartPieVo;
import com.yyds.vo.NatHospitalVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 请不要模仿我
 *
 * @author lxy
 * com.yyds.controller.
 */
@RestController
@RequestMapping("/natsites")
public class NatSitesController {
    @Autowired
    private NatSitesService natSitesService;


    // natsites/sitesList
    @RequestMapping("/sitesList")
    public MyJSON<NatHospitalVo> findAllNatSites(@RequestParam Map<String,Object> params){

        return natSitesService.findAllNatSites(params);

    }

    @GetMapping("/deleteNatSites")
    public R deleteNatSites(Integer id){
        //根据id 删除学生信息
        int result = natSitesService.deleteByPrimaryKey(id);
        if(result==1){
            return R.ok();
        }else{
            return  R.error();
        }
    }
    //添加信息
    @PostMapping("/addNatSites")
    public R addNatSites(NatSites natSites){
        System.out.println("addsit"+natSites);
        int result = natSitesService.insertSelective(natSites);

        if(result==1){
            return R.ok();
        }else{
            return  R.error();
        }
    }

    //修改信息
    @PostMapping("/updateNatSites")
    public R updateNatSites(NatSites natSites){
        System.out.println(natSites);

        int result = natSitesService.updateByPrimaryKeySelective(natSites);

        if(result==1){
            return R.ok();
        }else{
            return  R.error();
        }
    }
    //查询医院与医生的关联信息。医生与医院未关联的信息不查
    //natsites/addfindAll
    @RequestMapping("/addfindAll")
    public List<Integer> addfindAll(){
       List<Integer> list =natSitesService.findHospital();
        return list;
    }
    // natsites/addfindAllDoctor
    // natsites/deleteAllSites
    @RequestMapping("/addfindAllDoctor")
    public List<Integer> addfindAllDoctor(@RequestParam Map<String,Object> params){
        List<Integer> list =natSitesService.addfindAllDoctor(params);
        return list;
    }
    @RequestMapping("/echartBar")
    public R echartBar(){

        List<EchartPieVo> list = natSitesService.personData();
        return R.ok().data("sexBar",list);
    }

    @RequestMapping("/deleteAllSites")
        public R deleteAll(String str){
            int count=natSitesService.deleteAll(str);
            return count > 0 ? R.ok() : R.error();
        }
}
